import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../provider/details_info.dart';
import './details_page/details_page_top.dart';
import './details_page/details_explain.dart';
import './details_page/details_tab.dart';
import './details_page/deatils_web.dart';
import './details_page/details_bottom.dart';

class DetailsPage extends StatelessWidget {
  final String goodsId;
  const DetailsPage({Key key, this.goodsId}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: IconButton(
          onPressed: (){ Navigator.pop(context); },
          icon: Icon(Icons.arrow_back),
        ),
        title: Text('商品详情页'),
      ),
      body: FutureBuilder(
        future: _getDetailData(context),
        builder: (context, snapshot) {
          if(snapshot.hasData) {
            return Stack(
              children: <Widget>[
                ListView(
                  children: <Widget>[
                    DetailsPageTop(),
                    DetailsWxplain(),
                    DetailsTab(),
                    DetailsWeb(),
                  ],
                ),
                Positioned(
                  left: 0,
                  bottom: 0,
                  child: DetailsBottom(),
                )
              ],
            );
          } else {
            return Center(
              child: Text('加载中...'),
            );
          }
        },
      ),
    );
  }  

  Future _getDetailData(context) async {
    await Provider.of<DetaiInfoProvider>(context, listen: false).getGoodsInfo(goodsId);
    return 'loaded';
  }
}